from enum import Enum
from typing import List, Optional

from pydantic import BaseModel, Field


class DNSRecordStatus(str, Enum):
    active = "active"
    paused = "paused"


class DNSRecordType(str, Enum):
    a = "A"
    aaaa = "AAAA"
    cname = "CNAME"
    txt = "TXT"
    mx = "MX"
    ns = "NS"
    srv = "SRV"


class DNSRecordBase(BaseModel):
    # provider: str = Field(..., description="云厂商")  # Removed
    credential_id: str = Field(..., description="凭据ID")
    domain: str = Field(..., description="主域名，例如 example.com")
    record_type: DNSRecordType = DNSRecordType.txt
    name: str = Field(..., description="主机记录")
    value: str = Field(..., description="记录值")
    ttl: int = Field(default=600, description="TTL（秒）")


class DNSRecordCreate(DNSRecordBase):
    status: DNSRecordStatus = DNSRecordStatus.active


class DNSRecordUpdate(BaseModel):
    id: str
    credential_id: str = Field(..., description="凭据ID")
    record_type: Optional[DNSRecordType] = None
    name: Optional[str] = None
    value: Optional[str] = None
    ttl: Optional[int] = None
    status: Optional[DNSRecordStatus] = None


class DNSRecordIdentifier(BaseModel):
    id: str
    credential_id: str = Field(..., description="凭据ID")


class DNSRecordBatchDeleteRequest(BaseModel):
    ids: List[str]
    credential_id: str = Field(..., description="凭据ID")


class DNSRecord(BaseModel):
    id: str
    provider: str
    domain: str
    record_type: DNSRecordType
    name: str
    value: str
    ttl: int
    status: DNSRecordStatus


class DomainSummary(BaseModel):
    domain: str
    provider: str
    record_count: int


class DomainListRequest(BaseModel):
    credential_id: Optional[str] = None


class DNSRecordListRequest(BaseModel):
    domain: Optional[str] = None
    credential_id: Optional[str] = None
